﻿@model IEnumerable<Models.ItemList>

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <environment include="Development">
        <link rel="stylesheet" href="~/layer/css/layui.css" media="all" />
        <link rel="stylesheet" href="~/layer/css/admin.css" media="all" />
    </environment>
    <environment exclude="Development">
        <link rel="stylesheet" href="~/layer/css/layui.css" asp-append-version="true" media="all" />
        <link rel="stylesheet" href="~/layer/css/admin.css" asp-append-version="true" media="all" />
    </environment>
</head>
<body id="iosiframe">
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">提现记录</div>
                    <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">状态</label>
                                <div class="layui-input-block">
                                    <select name="type">
                                        @foreach (var m in Model) {
                                            <option value="@m.value">@m.text</option>
                                        }
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline">
                                <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-search">
                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                </button>
                            </div>
                        </div>
                    </div>

                    <div class="layui-card-body">

                        @if ((Code.UserTypes)ViewData["userType"] != Code.UserTypes.普通用户) {
                            <div style="padding-bottom: 10px;">
                                <button class="layui-btn layuiadmin-btn-admin" data-type="batchdel">设置提现信息</button>
                            </div>
                        }
                        <table class="layui-hide" id="table-page" lay-filter="table" lay-size="lg"></table>

                        @if ((Code.UserTypes)ViewData["userType"] != Code.UserTypes.普通用户) {
                            <script type="text/html" id="buttonTpl">
                                <a class="layui-btn layui-btn-xs" lay-event="see"><i class="layui-icon layui-icon-search"></i>查看</a>
                                {{# if(d.Status == 1) { }}
                                <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="look"><i class="layui-icon layui-icon-vercode"></i>同意</a>
                                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>取消</a>
                                {{# } else { }}
                                <a class="layui-btn layui-btn-xs layui-btn-normal layui-btn-disabled" lay-event="look"><i class="layui-icon layui-icon-vercode"></i>同意</a>
                                <a class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" lay-event="del"><i class="layui-icon layui-icon-delete"></i>取消</a>
                                {{# } }}
                            </script>
                        }
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-fluid" id="ex" style="display:none;">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body">
                        <div class="layui-form" action="" lay-filter="">
                            <div class="layui-form-item">
                                <label class="layui-form-label">提现手续费</label>
                                <div class="layui-input-inline"><input type="text" maxlength="20" id="fee" name="fee" placeholder="" lay-verify="" class="layui-input"></div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label"></label>
                                <div class="layui-form-mid">设置手续费，可输入小数或带百分号的数字。如：0.02 或 2%</div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">可提现时间</label>
                                <div class="layui-input-inline"><input type="text" maxlength="20" id="time" name="time" placeholder="" lay-verify="" class="layui-input"></div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label"></label>
                                <div class="layui-form-mid">设置每个月的提现时间，如有多个请用“,”分隔</div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">提现倍数</label>
                                <div class="layui-input-inline"><input type="number" maxlength="20" value="1" id="multiple" name="multiple" placeholder="" lay-verify="" class="layui-input"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-fluid" id="cash" style="display:none;">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body">
                        <div class="layui-form" action="" lay-filter="">
                            <div class="layui-form-item">
                                <label class="layui-form-label">提现方式</label>
                                <div class="layui-form-mid" id="type"></div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label" id="lbAccount">银行卡号</label>
                                <div class="layui-form-mid" id="account"></div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label" id="lbName">收款账号</label>
                                <div class="layui-form-mid" id="name"></div>
                            </div>
                            <div class="layui-form-item" id="divBank">
                                <label class="layui-form-label">收款户名</label>
                                <div class="layui-form-mid" id="bank"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="~/layer/layui.js"></script>
    <script>
        layui.config({
            base: '../../layer/' //静态资源所在路径
        }).extend({
            index: 'index' //主入口模块
        }).use(['form', 'index', 'table'], function () {
            var $ = layui.$
                , form = layui.form
                , table = layui.table;

            var ua = navigator.userAgent.toLowerCase();
            var screenwidth = window.screen.width;
            if (!/iphone|ipad|ipod/.test(ua)) {
                $("#iosiframe").attr("scrolling", "auto");
            } else {
                $('#iosiframe').width(screenwidth + 'px');
            }

            $.ajax({
                url: '@Url.Action("GetCashLogListColumns", "api")',
                dataType: 'json',
                contentType: 'application/json',
                type: 'get'
            }).fail(function (jqXHR, textStatus, errorThrown) {
                alert(errorThrown, { icon: 2, title: textStatus });
                }).done(function (res) {
                    //res.splice(0, 0, { type: 'checkbox' });
                    res.push({ width: 206, align: 'center',  toolbar: '#buttonTpl' });

                    var tableIns = table.render({
                        elem: '#table-page'
                        , cellMinWidth: 80
                        , limit: 30
                        , url: '@Url.Action("CashLogsList", "api",new {  userId = (ViewData["userType"].ToString() == ((int)Code.UserTypes.普通用户).ToString() ? ViewData["Id"] : "0") })'
                        , toolbar: true
                        , defaultToolbar: ['filter', 'print', 'exports']
                        , cols: [res]
                        , parseData: function (res) {
                            return {
                                code: 0,
                                msg: "",
                                count: res.count,
                                data: JSON.parse(res.data)
                            }
                        }
                        , page: true
                    });

                    table.on('tool(table)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                        var data = obj.data; //获得当前行数据
                        var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）

                        if (layEvent === 'del') { //删除
                            layer.confirm('确定要取消该提现吗？', function (index) {
                                change(data.Id, tableIns, @((int)Code.CashStatus.取消));
                            });
                        } else if (layEvent === 'look') {
                            layer.confirm('确定要同意该提现吗？', function (index) {
                                change(data.Id, tableIns, @((int)Code.CashStatus.已处理));
                            });
                        } else if (layEvent === 'see') {
                            $.ajax({
                                url: '@Url.Action("GetUserCashInfo", "api")?id=' + data.UserId,
                                dataType: 'json'
                            }).fail(function (jqXHR, textStatus, errorThrown) {
                                alert(errorThrown, { icon: 2, title: textStatus });
                            }).done(function (res) {
                                if (res.code == 0) {
                                    $('#type').text(res.data.strCashType);
                                    $('#account').text(res.data.account);
                                    $('#name').text(res.data.name);
                                    $('#bank').text(res.data.bank);

                                    if (res.data.cashType == 1) {
                                        $('#lbAccount').text('银行卡号');
                                        $('#lbName').text('收款账号');
                                        $('#divBank').show();
                                    } else {
                                        if (res.data.cashType == 2) {
                                            $('#lbAccount').text('账 户');
                                        } else {
                                            $('#lbAccount').text('微信号');
                                        }
                                        $('#lbName').text('姓 名');
                                        $('#divBank').hide();
                                    }

                                    var layerIndex = layer.open({
                                        type: 1,
                                        title: '提现信息',
                                        closeBtn: false,
                                        shade: 0.8,
                                        area: ['620px'],
                                        content: $('#cash'),
                                        btn: ['关闭'],
                                        btnAlign: 'c'
                                    });
                                }
                            });
                        }
                    });

                    var active = {
                        batchdel: function () {
                            $.ajax({
                                url: '@Url.Action("GetHandlingfee", "api")',
                                dataType: 'json'
                            }).fail(function (jqXHR, textStatus, errorThrown) {
                                alert(errorThrown, { icon: 2, title: textStatus });
                            }).done(function (res) {
                                if (res.code == 0) {
                                    $('#fee').val(res.data.fee);
                                    $('#time').val(res.data.time);
                                    $('#multiple').val(res.data.multiple);

                                    var layerIndex = layer.open({
                                        type: 1,
                                        title: '提现信息',
                                        closeBtn: false,
                                        shade: 0.8,
                                        area: ['620px'],
                                        content: $('#ex'),
                                        btn: ['提交', '取消'],
                                        btnAlign: 'c',
                                        yes: function () {
                                            var fee = $('#fee').val(),
                                                multiple = $('#multiple').val(),
                                                time = $('#time').val();

                                            $.ajax({
                                                url: '@Url.Action("SetHandlingfee", "api")',
                                                dataType: 'json',
                                                contentType: 'application/json',
                                                data: JSON.stringify({ fee: fee, time: time, multiple: multiple }),
                                                type: 'post'
                                            }).fail(function (jqXHR, textStatus, errorThrown) {
                                                alert(errorThrown, { icon: 2, title: textStatus });
                                            }).done(function (res) {
                                                layer.msg(res.message, { offset: '15px', icon: (res.code == 0 ? 1 : 2), time: 1000 }, function (index) {
                                                    if (res.code == 0) {
                                                        layer.close(layerIndex);
                                                    }
                                                });
                                            });
                                        }
                                    });
                                }
                            });
                        }, add: function (obj) {

                        }
                    }

                    $('.layui-btn.layuiadmin-btn-admin').on('click', function () {
                        var type = $(this).data('type');
                        active[type] ? active[type].call(this) : '';
                    });

                    var change = function (id, table, status) {
                        $.ajax({
                            url: '@Url.Action("ChangeCashLog", "api")'
                            , dataType: 'json'
                            , data: JSON.stringify({ id: id, status: status })
                            , contentType: 'application/json'
                            , type: 'post'
                        }).fail(function (jqXHR, textStatus, errorThrown) {
                            alert(errorThrown, { icon: 2, title: textStatus });
                        }).done(function (res) {
                            layer.msg(res.message, { offset: '15px', icon: (res.code == 0 ? 1 : 2), time: 1000 });

                            if (res.code == 0) {
                                table.reload();
                            }
                        });
                    }

                    form.on('submit(LAY-user-back-search)', function (data) {
                        var field = data.field;

                        //执行重载
                        tableIns.reload({
                            where: field
                        });
                    });
                });
        });
    </script>
</body>
</html>
